﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;
using FeedReader.Shared;
using FeedReader.Shared.Data;
using System.IO;

namespace FeedReader.Shared.Workers
{
    public class OPMLWorker
    {
        CloudStorageAccount acc;
        CloudBlobClient blobclient;
        CloudBlobContainer opmlcontainer;

        public OPMLWorker(CloudStorageAccount newacc)
        {
            acc = newacc;
            blobclient = acc.CreateCloudBlobClient();
            opmlcontainer = blobclient.GetContainerReference(FeedReader.Shared.Data.ContainerNameServices.OPML);
        }

        public IQueryable<OPMLItem>readOPMLBlob(string blobref){
            CloudBlob opmlfile = opmlcontainer.GetBlobReference(blobref);
            string content = opmlfile.DownloadText();

            OPMLReader reader = OPMLReader.CreateFromString(content);

            return reader.Items();
        }
    }
}
